

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
    <meta name="description" content="@[toc] 运行环境  VMware  Centos7 虚拟机操作系统 Docker Jdk8 Hadoop3.1.3 scala 2.11.8 flink-1.9.1 Maven3.6.3 IDEA  注：在搭建Flink集群时需有Hadoop环境，尽管案例里没有用到HDFS，但通过资源调度管理的yarn组件启动Flink-shell 会有更好的效果。 关于Docker搭建Hadoop集群可以">
<meta property="og:type" content="article">
<meta property="og:title" content="大数据应用技术_使用 Docker搭建 Flink 集群_FlinkStreaming实时数据流处理程序实现词频统计">
<meta property="og:url" content="http://example.com/2021/12/23/%E5%A4%A7%E6%95%B0%E6%8D%AE%E5%BA%94%E7%94%A8%E6%8A%80%E6%9C%AF%20_%20%E4%BD%BF%E7%94%A8%20Docker%E6%90%AD%E5%BB%BA%20Flink%20%E9%9B%86%E7%BE%A4%20_%20FlinkStreaming%E5%AE%9E%E6%97%B6%E6%95%B0%E6%8D%AE%E6%B5%81%E5%A4%84%E7%90%86%E7%A8%8B%E5%BA%8F%E5%AE%9E%E7%8E%B0%E8%AF%8D%E9%A2%91%E7%BB%9F%E8%AE%A1/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="@[toc] 运行环境  VMware  Centos7 虚拟机操作系统 Docker Jdk8 Hadoop3.1.3 scala 2.11.8 flink-1.9.1 Maven3.6.3 IDEA  注：在搭建Flink集群时需有Hadoop环境，尽管案例里没有用到HDFS，但通过资源调度管理的yarn组件启动Flink-shell 会有更好的效果。 关于Docker搭建Hadoop集群可以">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/4f22729d10524bf8b38ac5f8f9675ec6.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/6f763a779d944a1c8d7c7e657aab496b.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/8280a5f763c24771a7602a6b671c86dd.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/472ab05afef14d4badcfffe09aad62cd.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/c81acd3700584adbb90b8f18d665263d.png#pic">
<meta property="og:image" content="https://img-blog.csdnimg.cn/d01e3518ece24d94b41532e108682bb3.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/3a7db0ffe7434ee3b986c50bb5b56738.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/f696d5915f1c4725b073f63bdd413faa.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/6f33f868822440fe9a17a84ef2363978.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/a928c6b6d89d43529589d657c09bd147.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/4440701077204447b6cd94f15698aef3.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/5fbc68729c124284bef7ddedd13c33da.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/3420bce4d4684b1d8f7287345c375702.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/ad65c6165af647af9d3d5dcdc2c488e1.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/b3b02466dffd485783705690abc90f9a.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/acdf4cf7c11d4c6fb5ee513b1e0d863f.png#pic_center">
<meta property="article:published_time" content="2021-12-23T12:24:31.000Z">
<meta property="article:modified_time" content="2022-08-22T15:41:30.902Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="大数据">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/4f22729d10524bf8b38ac5f8f9675ec6.png#pic_center">
  
  
  
  <title>大数据应用技术_使用 Docker搭建 Flink 集群_FlinkStreaming实时数据流处理程序实现词频统计 - Hexo</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>尤 Ni&#39;s Blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="大数据应用技术_使用 Docker搭建 Flink 集群_FlinkStreaming实时数据流处理程序实现词频统计"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        John Doe
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2021-12-23 20:24" pubdate>
          2021年12月23日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          6.2k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          52 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">大数据应用技术_使用 Docker搭建 Flink 集群_FlinkStreaming实时数据流处理程序实现词频统计</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：1 小时前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <p>@[toc]</p>
<h1 id="运行环境"><a href="#运行环境" class="headerlink" title="运行环境"></a>运行环境</h1><hr>
<ul>
<li>VMware </li>
<li>Centos7 虚拟机操作系统</li>
<li>Docker</li>
<li>Jdk8</li>
<li>Hadoop3.1.3</li>
<li>scala 2.11.8</li>
<li>flink-1.9.1</li>
<li>Maven3.6.3</li>
<li>IDEA</li>
</ul>
<p><code>注</code>：在搭建Flink集群时需有Hadoop环境，尽管案例里没有用到HDFS，但通过资源调度管理的yarn组件启动Flink-shell 会有更好的效果。</p>
<p><strong>关于Docker搭建Hadoop集群可以参考这篇博文</strong> <a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/120737940">基于Docker搭建完全分布式集群</a></p>
<h1 id="1-安装、配置-Flink"><a href="#1-安装、配置-Flink" class="headerlink" title="1. 安装、配置 Flink"></a>1. 安装、配置 Flink</h1><hr>
<h2 id="1-1使用Xftp工具将Flink资源传入虚拟机"><a href="#1-1使用Xftp工具将Flink资源传入虚拟机" class="headerlink" title="1.1使用Xftp工具将Flink资源传入虚拟机"></a>1.1使用Xftp工具将Flink资源传入虚拟机</h2><p><img src="https://img-blog.csdnimg.cn/4f22729d10524bf8b38ac5f8f9675ec6.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h2 id="1-2-在虚拟机中将Flink资源传输到docker容器"><a href="#1-2-在虚拟机中将Flink资源传输到docker容器" class="headerlink" title="1.2 在虚拟机中将Flink资源传输到docker容器"></a>1.2 在虚拟机中将Flink资源传输到docker容器</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker <span class="hljs-built_in">cp</span> flink-1.9.1-bin-scala_2.11.tgz hadoop101:/opt/download</span><br></code></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/6f763a779d944a1c8d7c7e657aab496b.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h2 id="1-3-解压Flink资源并配置环境变量"><a href="#1-3-解压Flink资源并配置环境变量" class="headerlink" title="1.3 解压Flink资源并配置环境变量"></a>1.3 解压Flink资源并配置环境变量</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs shell">tar -zxvf flink-1.9.1-bin-scala_2.12.tgz -C ./<br><br>mv flink-1.9.2 flink<br><br>vim /etc/profile.d/home.sh<br><br>source /etc/profile<br></code></pre></td></tr></table></figure>
<p><img src="https://img-blog.csdnimg.cn/8280a5f763c24771a7602a6b671c86dd.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h1 id="2-Flink单节点测试"><a href="#2-Flink单节点测试" class="headerlink" title="2.Flink单节点测试"></a>2.Flink单节点测试</h1><hr>
<h2 id="2-1-在hadoop101节点启动zookeeper-和-hadoop-dfs-和-yarn"><a href="#2-1-在hadoop101节点启动zookeeper-和-hadoop-dfs-和-yarn" class="headerlink" title="2.1 在hadoop101节点启动zookeeper 和 hadoop dfs 和 yarn"></a>2.1 在hadoop101节点启动zookeeper 和 hadoop dfs 和 yarn</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs shell">zkServer.sh start<br><br>start-dfs.sh<br><br>start-yarn.sh<br></code></pre></td></tr></table></figure>
<p><img src="https://img-blog.csdnimg.cn/472ab05afef14d4badcfffe09aad62cd.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h2 id="2-2-以-Yarn方式启动-Flink-Scala"><a href="#2-2-以-Yarn方式启动-Flink-Scala" class="headerlink" title="2.2 以 Yarn方式启动 Flink Scala"></a>2.2 以 Yarn方式启动 Flink Scala</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs shell">./start-cluster.sh<br>./start-scala-shell.sh yarn<br></code></pre></td></tr></table></figure>
<p><img src="https://img-blog.csdnimg.cn/c81acd3700584adbb90b8f18d665263d.png#pic" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p>测试完毕后, <code>:q</code> 退出</p>
<h1 id="3-配置-flink集群"><a href="#3-配置-flink集群" class="headerlink" title="3.配置 flink集群"></a>3.配置 flink集群</h1><hr>
<p>在flink根目录下的conf文件夹中修改 <code>masters</code> 文件的内容为 </p>
<figure class="highlight apache"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs apache"><span class="hljs-attribute">hadoop101</span>:<span class="hljs-number">8081</span><br></code></pre></td></tr></table></figure>
<p>然后再修改workers文件夹的内容为</p>
<figure class="highlight smali"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs smali">Hadoop101<br>Hadoop102<br>Hadoop103<br></code></pre></td></tr></table></figure>
<p>配置 <code>flink-conf.yaml</code>文件:<br>将 <code>jobmanager.rpc.address</code> 的属性值设置为 <strong>hadoop101</strong><br>再添加一行 <code>taskmanager.tmp.dirs: /opt/module/flink/tmp</code> 指定flink任务的缓存目录</p>
<p>接下来，分发配置好的 Flink资源到其他节点，即 hadoop102 和 hadoop103</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs shell">scp -r ./flink hadoop103:/opt/module/flink<br>scp -r ./flink hadoop102:/opt/module/flink<br></code></pre></td></tr></table></figure>
<p><img src="https://img-blog.csdnimg.cn/d01e3518ece24d94b41532e108682bb3.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h1 id="4-外部测试FlinkStreaming词频统计程序"><a href="#4-外部测试FlinkStreaming词频统计程序" class="headerlink" title="4. 外部测试FlinkStreaming词频统计程序"></a>4. 外部测试FlinkStreaming词频统计程序</h1><hr>
<p>创建IDEA项目，需下载 <code>scala</code> 插件，给项目配置scala的SDK，笔者这里的版本号是2.11.8</p>
<h2 id="4-1-配置pom-xml-依赖"><a href="#4-1-配置pom-xml-依赖" class="headerlink" title="4.1 配置pom.xml 依赖"></a>4.1 配置pom.xml 依赖</h2><p><code>pom.xml</code></p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-meta">&lt;?xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span>?&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">project</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://maven.apache.org/POM/4.0.0&quot;</span></span><br><span class="hljs-tag">         <span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span><br><span class="hljs-tag">         <span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">modelVersion</span>&gt;</span>4.0.0<span class="hljs-tag">&lt;/<span class="hljs-name">modelVersion</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.ycc<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>wordcount<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>WordCount<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">packaging</span>&gt;</span>jar<span class="hljs-tag">&lt;/<span class="hljs-name">packaging</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.0<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">repositories</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">repository</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">id</span>&gt;</span>alimaven<span class="hljs-tag">&lt;/<span class="hljs-name">id</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>aliyun maven<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">url</span>&gt;</span>http://maven.aliyun.com/nexus/content/groups/public/<span class="hljs-tag">&lt;/<span class="hljs-name">url</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-name">repository</span>&gt;</span><br>	        <span class="hljs-tag">&lt;<span class="hljs-name">repository</span>&gt;</span><br>	            <span class="hljs-tag">&lt;<span class="hljs-name">id</span>&gt;</span>maven1<span class="hljs-tag">&lt;/<span class="hljs-name">id</span>&gt;</span><br>	            <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>maven1<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>	            <span class="hljs-tag">&lt;<span class="hljs-name">url</span>&gt;</span>http://repo.maven.apache.org/maven2<span class="hljs-tag">&lt;/<span class="hljs-name">url</span>&gt;</span><br>	        <span class="hljs-tag">&lt;/<span class="hljs-name">repository</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">repositories</span>&gt;</span><br><br>    <span class="hljs-tag">&lt;<span class="hljs-name">properties</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">flink.version</span>&gt;</span>1.9.1<span class="hljs-tag">&lt;/<span class="hljs-name">flink.version</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">properties</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">dependencies</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.flink<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>flink-scala_2.11<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>$&#123;flink.version&#125;<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.flink<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>flink-streaming-scala_2.11<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>$&#123;flink.version&#125;<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.flink<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>flink-clients_2.11<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>$&#123;flink.version&#125;<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br><br>            <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.scala-lang<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>scala-library<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.11.8<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">dependencies</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">build</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">sourceDirectory</span>&gt;</span>src/main/scala<span class="hljs-tag">&lt;/<span class="hljs-name">sourceDirectory</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">pluginManagement</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">pluginManagement</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">plugins</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">plugin</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>net.alchim31.maven<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>scala-maven-plugin<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">executions</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">execution</span>&gt;</span><br>                        <span class="hljs-tag">&lt;<span class="hljs-name">id</span>&gt;</span>compile-scala<span class="hljs-tag">&lt;/<span class="hljs-name">id</span>&gt;</span><br>                        <span class="hljs-tag">&lt;<span class="hljs-name">phase</span>&gt;</span>process-resources<span class="hljs-tag">&lt;/<span class="hljs-name">phase</span>&gt;</span><br>                        <span class="hljs-tag">&lt;<span class="hljs-name">goals</span>&gt;</span><br>                            <span class="hljs-tag">&lt;<span class="hljs-name">goal</span>&gt;</span>add-source<span class="hljs-tag">&lt;/<span class="hljs-name">goal</span>&gt;</span><br>                            <span class="hljs-tag">&lt;<span class="hljs-name">goal</span>&gt;</span>compile<span class="hljs-tag">&lt;/<span class="hljs-name">goal</span>&gt;</span><br>                        <span class="hljs-tag">&lt;/<span class="hljs-name">goals</span>&gt;</span><br>                    <span class="hljs-tag">&lt;/<span class="hljs-name">execution</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">execution</span>&gt;</span><br>                        <span class="hljs-tag">&lt;<span class="hljs-name">id</span>&gt;</span>scala-compile-first<span class="hljs-tag">&lt;/<span class="hljs-name">id</span>&gt;</span><br>                        <span class="hljs-tag">&lt;<span class="hljs-name">phase</span>&gt;</span>compile<span class="hljs-tag">&lt;/<span class="hljs-name">phase</span>&gt;</span><br>                        <span class="hljs-tag">&lt;<span class="hljs-name">goals</span>&gt;</span><br>                            <span class="hljs-tag">&lt;<span class="hljs-name">goal</span>&gt;</span>add-source<span class="hljs-tag">&lt;/<span class="hljs-name">goal</span>&gt;</span><br>                            <span class="hljs-tag">&lt;<span class="hljs-name">goal</span>&gt;</span>testCompile<span class="hljs-tag">&lt;/<span class="hljs-name">goal</span>&gt;</span><br>                        <span class="hljs-tag">&lt;/<span class="hljs-name">goals</span>&gt;</span><br>                    <span class="hljs-tag">&lt;/<span class="hljs-name">execution</span>&gt;</span><br>                <span class="hljs-tag">&lt;/<span class="hljs-name">executions</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">scalaVersion</span>&gt;</span>2.11.8<span class="hljs-tag">&lt;/<span class="hljs-name">scalaVersion</span>&gt;</span><br>                <span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-name">plugin</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">plugins</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">build</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">project</span>&gt;</span><br></code></pre></td></tr></table></figure>

<h2 id="4-2-编写词频统计的Flink程序"><a href="#4-2-编写词频统计的Flink程序" class="headerlink" title="4.2 编写词频统计的Flink程序"></a>4.2 编写词频统计的Flink程序</h2><p><code>WordCount.scala</code></p>
<p>这个程序主要就是使用 Flink 的API方法进行词频统计，通过flatMap转换操作将每一行的数据源根据空格进行分隔，并把所有字母统一为小写，之后再使用map操作使其变为key-value键值对，即（单词, 出现频数），最后在进行分组、求和，就得出了最终的词频统计结果 。当在IDEA中执行时，使用的是IDEA本地环境，没有发布到Flink集群环境上，故可直接在IDEA中进行测试。</p>
<figure class="highlight scala"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><code class="hljs scala"><span class="hljs-keyword">package</span> com.ycc<br><br><span class="hljs-keyword">import</span> org.apache.flink.api.scala._<br><br><span class="hljs-class"><span class="hljs-keyword">object</span> <span class="hljs-title">WordCount</span> </span>&#123;<br>  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">main</span></span>(args: <span class="hljs-type">Array</span>[<span class="hljs-type">String</span>]): <span class="hljs-type">Unit</span> = &#123;<br><br>    <span class="hljs-comment">//第1步：建立执行环境</span><br>    <span class="hljs-keyword">val</span> env = <span class="hljs-type">ExecutionEnvironment</span>.getExecutionEnvironment<br><br>    <span class="hljs-comment">//第2步：创建数据源</span><br>    <span class="hljs-keyword">val</span> text = env.fromElements(<br>      <span class="hljs-string">&quot;hello, world!&quot;</span>,<br>      <span class="hljs-string">&quot;hello, world!&quot;</span>,<br>      <span class="hljs-string">&quot;hello, world!&quot;</span>)<br><br>    <span class="hljs-comment">//第3步：对数据集指定转换操作</span><br>    <span class="hljs-keyword">val</span> counts = text.flatMap &#123; _.toLowerCase.split(<span class="hljs-string">&quot; &quot;</span>) &#125;<br>      .map &#123; (_, <span class="hljs-number">1</span>) &#125;<br>      .groupBy(<span class="hljs-number">0</span>)<br>      .sum(<span class="hljs-number">1</span>)<br><br>    <span class="hljs-comment">// 第4步：输出结果</span><br>    counts.print()<br>  &#125;<br>&#125;<br></code></pre></td></tr></table></figure>
<p><code>StreamWordCount.scala</code></p>
<p>与上个程序的不同是其数据源来自于IP:端口号的形式，通过在Flink集群的节点，即hadoop101节点向一个端口发送消息，然后程序向这个端口获取数据，获取后进行词频套机的操作，不同于之前，它用到了timeWindow窗口，而且最终有使用execute方法提交这个Job任务。</p>
<figure class="highlight scala"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><code class="hljs scala"><span class="hljs-keyword">package</span> com.ycc<br><br><span class="hljs-keyword">import</span> org.apache.flink.streaming.api.scala._<br><span class="hljs-keyword">import</span> org.apache.flink.streaming.api.scala.<span class="hljs-type">StreamExecutionEnvironment</span><br><span class="hljs-keyword">import</span> org.apache.flink.streaming.api.windowing.time.<span class="hljs-type">Time</span><br><br><span class="hljs-class"><span class="hljs-keyword">object</span> <span class="hljs-title">StreamWordCount</span></span>&#123;<br>  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">main</span></span>(args: <span class="hljs-type">Array</span>[<span class="hljs-type">String</span>]): <span class="hljs-type">Unit</span> = &#123;<br><br>    <span class="hljs-comment">//第1步：建立执行环境</span><br>    <span class="hljs-keyword">val</span> env = <span class="hljs-type">StreamExecutionEnvironment</span>.getExecutionEnvironment<br><br>    <span class="hljs-comment">//第2步：创建数据源</span><br>    <span class="hljs-keyword">val</span> source = env.socketTextStream(<span class="hljs-string">&quot;hadoop101&quot;</span>,<span class="hljs-number">9999</span>,&#x27;\n&#x27;)<br><br>    <span class="hljs-comment">//第3步：对数据集指定转换操作逻辑</span><br>    <span class="hljs-keyword">val</span> dataStream = source.flatMap(_.split(<span class="hljs-string">&quot; &quot;</span>))<br>      .map((_,<span class="hljs-number">1</span>))<br>      .keyBy(<span class="hljs-number">0</span>)<br>      .timeWindow(<span class="hljs-type">Time</span>.seconds(<span class="hljs-number">2</span>),<span class="hljs-type">Time</span>.seconds(<span class="hljs-number">2</span>))<br>      .sum(<span class="hljs-number">1</span>)<br><br>    <span class="hljs-comment">//第4步：指定计算结果输出位置</span><br>    dataStream.print()<br><br>    <span class="hljs-comment">//第5步：指定名称并触发流计算</span><br>    env.execute(<span class="hljs-string">&quot;Flink Streaming Word Count&quot;</span>)<br>  &#125;<br>&#125;<br></code></pre></td></tr></table></figure>


<h2 id="4-3-启动-Flink集群-，测试词频统计程序"><a href="#4-3-启动-Flink集群-，测试词频统计程序" class="headerlink" title="4.3 启动 Flink集群 ，测试词频统计程序"></a>4.3 启动 Flink集群 ，测试词频统计程序</h2><p><img src="https://img-blog.csdnimg.cn/3a7db0ffe7434ee3b986c50bb5b56738.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p>第一个程序，IDEA中的执行结果</p>
<p><img src="https://img-blog.csdnimg.cn/f696d5915f1c4725b073f63bdd413faa.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>测试第二个程序前需在hadoop101节点监听9999端口号 并发送消息</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">nc -lk 9999<br></code></pre></td></tr></table></figure>
<p><img src="https://img-blog.csdnimg.cn/6f33f868822440fe9a17a84ef2363978.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>第二个程序， FlinkStreaming程序在IDEA中的执行结果<br><img src="https://img-blog.csdnimg.cn/a928c6b6d89d43529589d657c09bd147.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h1 id="5-本地测试-将打包的FlinkStream程序-提交到Flink集群"><a href="#5-本地测试-将打包的FlinkStream程序-提交到Flink集群" class="headerlink" title="5. 本地测试 将打包的FlinkStream程序 提交到Flink集群"></a>5. 本地测试 将打包的FlinkStream程序 提交到Flink集群</h1><hr>
<h2 id="5-1-在IDEA使用Maven打包FLink项目"><a href="#5-1-在IDEA使用Maven打包FLink项目" class="headerlink" title="5.1 在IDEA使用Maven打包FLink项目"></a>5.1 在IDEA使用Maven打包FLink项目</h2><p><img src="https://img-blog.csdnimg.cn/4440701077204447b6cd94f15698aef3.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h2 id="5-2-在Flink集群节点执行jar包"><a href="#5-2-在Flink集群节点执行jar包" class="headerlink" title="5.2  在Flink集群节点执行jar包"></a>5.2  在Flink集群节点执行jar包</h2><p>在代码中，需监听hadoop101节点的端口，故在hadoop102节点提交Flink包<br>测试第一个程序的结果: </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">flink run --class com.ycc.WordCount ./wordcount-1.0.jar<br></code></pre></td></tr></table></figure>
<p><img src="https://img-blog.csdnimg.cn/5fbc68729c124284bef7ddedd13c33da.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>测试第二个程序出现报错<br><img src="https://img-blog.csdnimg.cn/3420bce4d4684b1d8f7287345c375702.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br><img src="https://img-blog.csdnimg.cn/ad65c6165af647af9d3d5dcdc2c488e1.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>通过访问Flink web 页面，地址: <a target="_blank" rel="noopener" href="http://hadoop101:8081/%E6%9F%A5%E7%9C%8B%E6%8A%A5%E9%94%99%E4%BF%A1%E6%81%AF">http://hadoop101:8081/查看报错信息</a></p>
<p><img src="https://img-blog.csdnimg.cn/b3b02466dffd485783705690abc90f9a.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>根据报错提示，发现出错原因是端口占用，可能是因为之前测试9999端口时，没有正常退出，现尝试将StreamWordCount.scala程序val source &#x3D; env.socketTextStream(“hadoop101”,9999,’\n’)<br>这部分中的9999端口号改为12345，并重新打包，传输到docker容器，在提交任务前，需先打开hadoop101节点的监听端口 <code>nc -lk 12345</code>，再提交jar包，命令如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs shell">nc -lk 12345<br><br>flink run --class com.ycc.StreamWordCount ./wordcount-1.0.jar<br></code></pre></td></tr></table></figure>
<p>查询词频统计输出的结果</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">tail -f ./log/flink*.out<br></code></pre></td></tr></table></figure>
<p>因为没有使用后台执行的参数，现使用第三个节点通过ssh命令远程登陆hadoop102查看结果，最后的词频统计结果如下:<br><img src="https://img-blog.csdnimg.cn/acdf4cf7c11d4c6fb5ee513b1e0d863f.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>至此，已完成了 Flink集群的搭建以及 FlinkStreaming操作进行词频统计。</p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E5%A4%A7%E6%95%B0%E6%8D%AE/" class="category-chain-item">大数据</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/%E5%A4%A7%E6%95%B0%E6%8D%AE/">#大数据</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>大数据应用技术_使用 Docker搭建 Flink 集群_FlinkStreaming实时数据流处理程序实现词频统计</div>
      <div>http://example.com/2021/12/23/大数据应用技术 _ 使用 Docker搭建 Flink 集群 _ FlinkStreaming实时数据流处理程序实现词频统计/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>John Doe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2021年12月23日</div>
        </div>
      
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2021/12/24/Web%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%20_%20%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv1.0%20_%20%E5%BC%80%E5%8F%91%E8%AE%B0%E5%BD%95%EF%BC%88%E4%BA%94%EF%BC%89%20_%20%E6%A8%A1%E6%8B%9F%E7%BD%91%E7%AB%99%E5%9F%8B%E7%82%B9%E5%AE%9E%E7%8E%B0%E7%94%A8%E6%88%B7%E6%B5%8F%E8%A7%88%E8%AE%B0%E5%BD%95%E7%9A%84%E7%BB%9F%E8%AE%A1%E4%B8%8E%E6%98%BE%E7%A4%BA/" title="Web项目实战 _ 购物系统v1.0 _ 开发记录（五） _ 模拟网站埋点实现用户浏览记录的统计与显示">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Web项目实战 _ 购物系统v1.0 _ 开发记录（五） _ 模拟网站埋点实现用户浏览记录的统计与显示</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2021/12/23/Web%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%20_%20%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv1.0%20_%20%E5%BC%80%E5%8F%91%E8%AE%B0%E5%BD%95%EF%BC%88%E5%9B%9B%EF%BC%89%20_%20%E5%AE%9E%E7%8E%B0JQuery%E5%9B%BE%E7%89%87%E4%B8%8A%E4%BC%A0%20_%20%E4%BD%BF%E7%94%A8JQ%E6%8F%92%E4%BB%B6%E6%8F%90%E4%BA%A4AJAX%E8%AF%B7%E6%B1%82%E5%AE%9E%E7%8E%B0%E5%8F%91%E5%B8%83%E5%95%86%E5%93%81%E5%B9%B6%E4%BF%9D%E5%AD%98%E5%88%B0%E6%95%B0%E6%8D%AE%E5%BA%93%20_%20%E5%95%86%E5%93%81%E5%88%86%E7%B1%BB%E5%88%86%E9%A1%B5%E6%98%BE%E7%A4%BA/" title="Web项目实战 _ 购物系统v1.0 _ 开发记录（四） _ 实现JQuery图片上传 _ 使用JQ插件提交AJAX请求实现发布商品并保存到数据库 _ 商品分类分页显示">
                        <span class="hidden-mobile">Web项目实战 _ 购物系统v1.0 _ 开发记录（四） _ 实现JQuery图片上传 _ 使用JQ插件提交AJAX请求实现发布商品并保存到数据库 _ 商品分类分页显示</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
